package top.tocchen.bookshop.controller;

import top.tocchen.bookshop.util.DateFormat;
import top.tocchen.bookshop.entity.BookEntity;
import top.tocchen.bookshop.service.impl.SearchServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;


/**
 * @author tocchen
 * @date 2022/8/9 19:34
 * @since jdk 1.8
 **/
@Controller
public class BookController {
    @Autowired
    SearchServiceImpl searchService;

    @RequestMapping("/book")
    public String gobook( ModelMap map,@RequestParam("bookid") Integer bookid){
        BookEntity byBookId = searchService.findByBookId(bookid);
        map.addAttribute("book",byBookId);
        map.addAttribute("Bookdate", DateFormat.formatDateToDay(byBookId.getPublishDate()));
        map.addAttribute("category",searchService.categoryfindById(byBookId.getCategoryId()));
        return "book";
    }
}
